package com.panopset.io;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import com.panopset.compat.Strings;

/**
 * Store contents of a text list in a file.
 * @author Karl Dinwiddie
 *
 */
public final class FileTextList {

    /**
     * List of text file lines.
     */
    private final List<String> lb;

    /**
     *
     * @param lines Text file lines.
     */
    public FileTextList(final List<String> lines) {
        lb = lines;
    }

    /**
     *
     * @param file File to save text list to.
     */
    public void save(final File file) {
        try (FileWriter fw = new FileWriter(file);
                BufferedWriter bw = new BufferedWriter(fw);) {
            String eol = new Strings().getEol();
            for (String s : lb) {
                bw.write(s);
                bw.write(eol);
            }
            bw.flush();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}
